home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
- See the Modification History for more details.
-
- This file is based upon work produced by Greg Anderson (Apple DTS).
-
- Product
- About Box
-
- FILE
- ABUText.c
-
- NAME
- ABUText.c, part of the ABox project source code,
- responsible for mix-in handling the AboutBox text
- utilities stuff, such as scroll bar synchronization, line
- heights, etc.
-
- DESCRIPTION
- This file contains defines for the about box modules.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 10 June 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
-
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABUText.h"
-
- /*=============== Globals ================*/
-
-
- /*================ CODE ==================*/
-
-
- /*=============================== ABUText::ABUText ================================*/
- ABUText::ABUText(void)
- {
- } // end ABUText
-
-
- /*=============================== ABUText::~ABUText ================================*/
- ABUText::~ABUText(void)
- {
- } // end ~ABUText
-
-
-
-
- /*=============================== ABUText::TEGetSelect ==================================*/
- //
- // Get the current selection
-
- // is called by:
- // external code; this is a public method
- //
- void ABUText::TEGetSelect(short* selStart, short* selEnd, TEHandle te)
- {
- // metro: ty...addition to trap bad parameters
- if(!(selStart && selEnd && te))
- return;
-
- *selStart = (*te)->selStart;
- *selEnd = (*te)->selEnd;
- }
-
-
- /*=============================== ABUText::TEGetChars ==================================*/
- //
- // Get some characters from the TextEdit record
-
- // is called by:
- // external code; this is a public method
- //
- void ABUText::TEGetChars(char *buf, short from, short to, TEHandle te)
- {
- CharsHandle theText = NULL;
- short theState;
- unsigned char *ptr;
-
- // metro: ty...addition to trap bad parameters
- if (!te || !buf)
- return;
-
- theText = ::TEGetText(te);
-
- if (!theText)
- return;
-
- theState = ::HGetState((Handle) theText);
- ::HLock((Handle) theText);
- ptr = (unsigned char*) (*theText);
- ptr += from;
- ::BlockMove(ptr, buf, to - from);
- buf[to - from] = 0;
- ::HSetState((Handle) theText, theState);
- }
-
-
- /*=============================== ABUText::GetTEView ==================================*/
- //
- // Return the current view rectangle of the given textedit record
-
- // is called by:
- // ViewHeight
- //
- void ABUText::GetTEView(TEHandle te, Rect *viewRect)
- {
- // metro: ty...addition to trap bad parameters
- if(!(te && viewRect))
- return;
- *viewRect = (*te)->viewRect;
- }
-
- /*=============================== ABUText::TELines ==================================*/
- //
- // Return the number of lines in the current textedit buffer
- //
- // returns 0 if there are bad parameters.
- //
- // is called by:
- // TEHeight
- //
- short ABUText::TELines(TEHandle te)
- {
- // metro: ty...addition to trap bad parameters
- if (!te)
- return 0; // 1.0a2 SJ added the 0
- else
- return((*te)->nLines);
- }
-
- /*=============================== ABUText::TEHeight ==================================*/
- //
- // Return the pixel height of the current textedit buffer
-
- // is called by:
- // VScrollLocation
- // PinnedTEVScroll
- // TEVThumbScroll
- //
- short ABUText::TEHeight(TEHandle te)
- {
- // metro: ty...addition to trap bad parameters
- if(!te) // metro: ty...addition to trap bad parameters
- return 0;
- else
- return ::TEGetHeight(ABUText::TELines(te), 0, te);
- }
-
- /*=============================== ABUText::TELineHeight ==================================*/
- //
- // Return the number of pixels in one line
-
- // is called by:
- // PinnedTEVScroll
- // TEVThumbScroll
- // ScrollTELine
- // ScrollTEPage
- //
- short ABUText::TELineHeight(TEHandle te)
- {
- // metro: ty...addition to trap bad parameters
- if(!te)
- return 0;
-
- if((*te)->lineHeight == -1)
- return kTEUdefaultLineHeight;
- else
- return (*te)->lineHeight;
- }
-
- /*=============================== ABUText::GetTEVScroll ==================================*/
- //
- // Return the number of pixels to the current scroll location
-
- // is called by:
- // PinnedTEVScroll
- // TEVThumbScroll
- // VScrollLocation
- //
- short ABUText::GetTEVScroll(TEHandle te)
- {
- // metro: ty...addition to trap bad parameters
- if(!te)
- return 0; // 1.0a2 SJ added the 0
- else
- return ((*te)->viewRect.top - (*te)->destRect.top);
- }
-
- /*=============================== ABUText::ViewHeight ==================================*/
- //
- // Return the pixel height of the view rectangle
-
- // is called by:
- // PinnedTEVScroll
- // VScrollLocation
- // TEVThumbScroll
- // ScrollTEPage
- //
- short ABUText::ViewHeight(TEHandle te)
- {
- Rect viewRect;
-
- // metro: ty...addition to trap bad parameters
- if(!te)
- return 0;
-
- ABUText::GetTEView(te, &viewRect);
-
- return (viewRect.bottom - viewRect.top);
- }
-
- /*=============================== ABUText::VScrollLocation ==================================*/
- //
- // Return a number from 1 - 1000 (GetCtlMin() - GetCtlMax()) indicating the
- // current scroll location of the textedit record
-
- // is called by:
- // FixScrollBar
- //
- short ABUText::VScrollLocation(ControlHandle scrollbar)
- {
- long tmp;
-
- TEHandle te = (TEHandle) ::GetCRefCon(scrollbar);
-
- // metro: ty...addition to trap bad parameters
- if (!te)
- return 1;
- tmp = ABUText::GetTEVScroll(te) * (long) ::GetCtlMax(scrollbar);
- tmp /= (ABUText::TEHeight(te) - ABUText::ViewHeight(te));
-
- return tmp;
- }
-
- /*=============================== ABUText::PinnedTEVScroll ==================================*/
- //
- // Call TEScroll, but don't scroll past top or below bottom
- // This code also adjusts the scrollbar.
-
- // is called by:
- // TEVThumbScroll
- // ScrollTELine
- // ScrollTEPage
- //
- void ABUText::PinnedTEVScroll(TEHandle te, ControlHandle scrollbar, short dv)
- {
- short max;
- short lineh = ABUText::TELineHeight(te);
-
- // metro: ty...addition to trap bad parameters
- if(!(te && scrollbar))
- return;
-
- if(lineh == -1)
- lineh = kTEUdefaultLineHeight;
-
- if(dv > 0)
- {
- max = ABUText::GetTEVScroll(te);
- if(dv > max)
- dv = max;
- }
- else
- {
- max = ABUText::TEHeight(te) - ABUText::ViewHeight(te) - ABUText::GetTEVScroll(te) - 1;
- max = max - (max % lineh) + lineh;
- if(max < 0)
- max = 0;
- if((-dv) > max)
- dv = -max;
- }
-
- ::TEScroll(0,dv,te);
- ABUText::FixScrollBar(scrollbar);
- }
-
- /*=============================== ABUText::TEVThumbScroll ==================================*/
- //
- // Scroll directly to a new location.
- //
- // is called by:
- // TrackUpDownPage
- // ScrollBarClick
- //
- void ABUText::TEVThumbScroll(TEHandle te, ControlHandle scrollbar)
- {
- long newScroll;
- short deltaScroll;
-
- // metro: ty...addition to trap bad parameters
- if(!(te && scrollbar))
- return;
-
- /*
- // 'GetCtlValue' ranges from 0 to 1000. Convert this into a textedit range
- // of zero to (texteditHeight - viewHeight)
- */
-
- newScroll = ::GetCtlValue(scrollbar);
- newScroll *= (ABUText::TEHeight(te) -ABUText:: ViewHeight(te));
- newScroll /= (long)::GetCtlMax(scrollbar);
-
- /*
- // We don't want to scroll to just any pixel, though...
- */
-
- newScroll /= ABUText::TELineHeight(te);
- newScroll *= ABUText::TELineHeight(te);
-
- /*
- // Now find out where we are, and how far we have to move to get to
- // where we want to go.
- */
-
- deltaScroll = ABUText::GetTEVScroll(te) - newScroll;
- ABUText::PinnedTEVScroll(te, scrollbar, deltaScroll);
- }
-
- /*=============================== ABUText::ScrollTELine ==================================*/
- //
- // Scroll up or down one line
- //
- // is called by:
- // TrackUpDownArrows
- //
- void ABUText::ScrollTELine(TEHandle te, ControlHandle scrollbar, short dir)
- {
- // metro: ty...addition to trap bad parameters
- if (!(te && scrollbar))
- return;
-
- ABUText::PinnedTEVScroll(te, scrollbar, dir * ABUText::TELineHeight(te));
- }
-
- /*=============================== ABUText::ScrollTEPage ==================================*/
- //
- // Scroll up or down one page
- //
- // is called by:
- // TrackUpDownPage
- //
- void ABUText::ScrollTEPage(TEHandle te, ControlHandle scrollbar, short dir)
- {
- short linePix;
- short pagePix;
- short pageLines;
-
- // metro: ty...addition to trap bad parameters
- if (!(te && scrollbar))
- return;
-
- pagePix = ABUText::ViewHeight(te);
- linePix = ABUText::TELineHeight(te);
- pageLines = pagePix / linePix;
- pagePix = (pageLines - 1) * linePix;
-
- ABUText::PinnedTEVScroll(te, scrollbar, dir * pagePix);
- }
-
- /*=============================== ABUText::TrackUpDownArrows ==================================*/
- //
- // This routine is called repeatedly while the scroll bar is tracked.
- //
- // 1.0a2 SJ added the void return type below:
- //
- // is called by:
- // ScrollBarClick
- //
- pascal void ABUText::TrackUpDownArrows(ControlHandle theControl, short partCode)
- {
- TEHandle te;
-
- // begin here...
- // metro: ty...addition to trap bad parameters
- if (!theControl)
- return;
- else
- te = (TEHandle) ::GetCRefCon(theControl);
-
- if((te && theControl))
- switch(partCode)
- {
- case inUpButton:
-
- ABUText::ScrollTELine(te, theControl, kTEUscrollForwardOneUnit);
- break;
-
- case inDownButton:
-
- ABUText::ScrollTELine(te, theControl, kTEUscrollBackwardOneUnit);
- break;
-
- }
- }
-
- /*=============================== ABUText::TrackUpDownPage ==================================*/
- //
- // This routine is called repeatedly while the scroll bar is tracked.
- //
- // 1.0a2+ ty created from a copy of TrackUpDownArrows()
- //
- // is called by:
- // ScrollBarClick
- //
- pascal void ABUText::TrackUpDownPage(ControlHandle theControl, short partCode)
- {
- TEHandle te;
-
- // begin here...
- // metro: ty...addition to trap bad parameters
- if (!theControl)
- return;
- else
- te = (TEHandle) ::GetCRefCon(theControl);
-
- if((te && theControl))
- switch(partCode)
- {
- case inPageUp:
-
- ABUText::ScrollTEPage(te, theControl, kTEUscrollForwardOneUnit);
- break;
-
- case inPageDown:
-
- ABUText::ScrollTEPage(te, theControl, kTEUscrollBackwardOneUnit);
- break;
-
- case inThumb:
-
- ABUText::TEVThumbScroll(te, theControl);
- break;
-
- }
- }
-
- /*=============================== ABUText::ScrollBarClick ==================================*/
- //
- // Interact with a VERTICAL scroll bar
- //
- // Pass a handle to the scrollbar's control record and the point (in LOCAL
- // coordinates) where the mouse hit the scrollbar.
- //
- // WARNING: The refCon of the scrollbar MUST point to the textedit record
- // That it is associated with.
- //
- // is called by:
- // external code; this is called by the using-application
- //
-
- void ABUText::ScrollBarClick(ControlHandle scrollbar, Point where)
- {
- TEHandle te = NULL;
- ControlActionUPP actionUPP;
-
- /*
- // Ponnuki always sets the refCon of a scrollbar to the
- // TEHandle associated with that scrollbar
- */
-
- if (!scrollbar)
- {
- return;
- }
- else if ((*scrollbar)->contrlHilite == 255)
- {
- // control is not active, so bail out.
- return;
- }
-
- te = (TEHandle) ::GetCRefCon(scrollbar);
- if (!te)
- return;
-
- /*
- // TrackControl passes different parameters to 'trackAction' based on
- // what type of control it is tracking & what part of the control the
- // mouse is in. Therefore, we cannot simply use the same trackAction
- // procedure for every 'TrackControl' that might come through this
- // routine. :< Fortunately, we only need to call a 'trackAction'
- // proc for the up and down facing buttons.
- */
-
- switch(TestControl(scrollbar,where))
- {
- case inUpButton:
- case inDownButton:
-
- // do the power pc thing!
- actionUPP = NewControlActionProc(ABUText::TrackUpDownArrows);
- ::TrackControl(scrollbar,where, actionUPP);
- DisposeRoutineDescriptor(actionUPP);
- break;
-
- case inPageUp:
- case inPageDown:
-
- // do the power pc thing!
- actionUPP = NewControlActionProc(ABUText::TrackUpDownPage); // 1.0a4 ty fixed
- ::TrackControl(scrollbar, where, actionUPP);
- DisposeRoutineDescriptor(actionUPP);
- break;
-
- case inThumb:
-
- ::TrackControl(scrollbar,where, (ControlActionUPP) 0L); // 1.0a4 SJ cast
- ABUText::TEVThumbScroll(te, scrollbar);
- break;
- }
- }
-
- /*=============================== ABUText::FixScrollBar ==================================*/
- //
- // Fix a VERTICAL scroll bar after a TE field has been scrolled
- //
- // Pass a handle to the scrollbar's control record
- //
- // WARNING: The refCon of the scrollbar MUST point to the textedit record
- // That it is associated with.
- //
- // is called by:
- // PinnedTEVScroll
- //
- void ABUText::FixScrollBar(ControlHandle scrollbar)
- {
- //TEHandle te;
-
- /*
- // Ponnuki always sets the refCon of a scrollbar to the
- // TEHandle associated with that scrollbar
- */
-
- if(!scrollbar)
- return;
-
- //te = (TEHandle) GetCRefCon(scrollbar);
- ::SetCtlValue(scrollbar, ABUText::VScrollLocation(scrollbar));
- ::Draw1Control(scrollbar);
- }
-